var shopSearch = {};
//页面加载事件
$(function(){
    //初始化标签页
    shopSearch.methods.tabInit(this);
    //初始化滚动
    shopSearch.methods.SliderInit(this);
    //监听，分页数字输入
    shopSearch.methods.InputNum(this);
    //加入购物车动画，添加
    shopSearch.methods.FlyCartInit(this);
});
shopSearch.data = {};
shopSearch.addEvent =function(obj){};
shopSearch.methods = {};
//初始化tab
shopSearch.methods.tabInit =function(obj){
    $(".shop-tabcontrol").each(function(val){
        var tab = new Controller.TabControl({
            container:$(this),
            tabNavItem:".shop-tab-nav-item",
            tabConItem:".shop-tab-con-item",
            tagName:"data-id",
            event:"mouseover"
        });
    });
};
//初始化滚动
shopSearch.methods.SliderInit = function(obj){
    $(".shop-tab-con-item").each(function(val){
        Controller.Slider({
            father: $(this),
            container:".shop-goods-list ul",
            prevBtn: ".shop-left-nav",
            nextBtn: ".shop-right-nav",
            itemSelector: "li",
            fatherSize: 1440
        });
    });
}
shopSearch.methods.InputNum = function(obj){
    $(".shop-page .shop-input").on("input",function(e){
        var _val  = $(this).val();
        var maxNum = $(this).attr("data-pageindex-max");
        var reg = /^[0-9]*$/;
        if(!reg.test(_val)){
            _val = _val.replace(/[^0-9]/ig,"");
            $(this).val(_val);
            return;
        }
        if(_val>maxNum){
            $(this).val(maxNum);
        }
    });
}
//购物加入动画
shopSearch.methods.FlyCartInit = function(obj){
	var offset = $(".shop-top .shop-top-menu .shop-icon-cart").offset();
	$(".shop-btn-add-cart").click(function(event){
        var addcar = $(this);
        event.preventDefault();
        event.stopPropagation();
		var img = $(this).parents(".shop-goods-item").find('.shop-goods-img img').attr('src');
		var flyer = $('<img width="100" height="100" class="shop-img-flyer" src="'+img+'">');
		flyer.fly({
			start: {
				left: event.pageX, //开始位置（必填）#fly元素会被设置成position: fixed
                top: event.pageY //开始位置（必填）
			},
			end: {
				left: offset.left+10, //结束位置（必填）
				top: offset.top+10, //结束位置（必填）
				width: 0, //结束时宽度
				height: 0 //结束时高度
			},
            onEnd: function(){ //结束回调
                //购物车数量加
                this.destory();
                //购物车添加动画，完成回调
                shopSearch.methods.OverAddCart();
			}
		});
	});
}
//购物车添加动画，完成回调
shopSearch.methods.OverAddCart = function(obj){

}